home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3755 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  51 lines

  1. Newsgroups: comp.lang.c++
  2. Path: wn.planet.gen.nz!news
  3. From: hugp@kp.planet.gen.nz (Peter Hug)
  4. Subject: [Q] Missinterpreting *protected* access modifier?
  5. X-Newsreader: Forte Free Agent 1.0.82
  6. Reply-To: hugp@kp.planet.gen.nz
  7. Sender: news@wn.planet.gen.nz (news)
  8. Organization: Maxi Solutions Ltd
  9. Message-ID: <DLrCGF.G1F@wn.planet.gen.nz>
  10. Date: Thu, 25 Jan 1996 23:11:17 GMT
  11.  
  12. Am I missinterpreting the meaning of the *protected* access modifier?
  13. The following code does not compile under VC++:
  14.  
  15.      ============================================
  16.      class A
  17.      {
  18.      protected:
  19.        int i;
  20.        int GetInt() { return i; };
  21.      };
  22.  
  23.      class B : public A
  24.      {
  25.      protected:
  26.        int Foo(A * pA) { return pA->GetInt(); };
  27.      };
  28.      ============================================
  29.  
  30. The error I'm getting is on the line declaring B::Foo(): error C2248:
  31. 'GetInt' : cannot access protected member declared in class 'A'
  32.  
  33. My C++ bible knows the following about the protected keyword: "When
  34. preceding a list of class members, the protected keyword specifies that
  35. those members are accessible only from member functions and friends of
  36. the class and its derived classes."
  37.                   ^^^^^^^^^^^^^^^
  38. According to this definition, B should have access to A::GetInt().
  39.  
  40. Cheers
  41.  
  42.  
  43. +-------------------------------------------------------------------+
  44. + Peter Hug                          mailto://hugp@kp.planet.gen.nz +
  45. + Maxi Solutions Ltd             http://kp.planet.gen.nz/users/hugp +
  46. + PO Box 1468                                                       +
  47. + Paraparaumu Beach                           Phone: +64 4 297-0463 +
  48. + New Zealand                                 Fax:   +64 4 297-0465 +
  49. +-------------------------------------------------------------------+
  50.  
  51.